<%@ page language="java" pageEncoding="us-ascii" contentType="text/html;charset=us-ascii" %>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<%--Copyright (C) 2011 Wolfgang Hankeln, Norma J. Wendel
	 
	This file is part of CDinFusion.
	
	CDinFusion is free software: you can redistribute it and/or
	modify it under the terms of the GNU Lesser General Public 
	License in version 3 (LGPL3) as published by the Free Software
	Foundation version 3 of the License.
	
	CDinFusion is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
	Lesser General Public License for more details.
	
	You should have received a copy of the Lesser General Public
	License along with CDinFusion; see the file COPYING. If not,
	write to the Free Software Foundation, 59 Temple Place - Suite 330,
	Boston, MA 02111-1307, USA or see <http://www.gnu.org/licenses/>.
	
	If you have any questions, send an email to: megx@mpi-bremen.de.
--%>
<%@ page import="java.util.ArrayList" %>
<%@ page import="org.cdinfusion.data.*"%>
<%@ page import="org.cdinfusion.data.environment.*"%>
<%@ page import="org.cdinfusion.data.studytype.*"%>
<%@ page import="java.util.List"%>

<%
System.out.println("<<<<<<<<<<3b_CD_INPUT_1tom>>>>>>>>>>");

String origin = (String) session.getAttribute("origin");
String context_exists = (String) session.getAttribute("context_exists");
String sessionID = session.getId();

List<CDElement> cdeLIST = (List<CDElement>) session.getAttribute("cdeLIST");
String message = "";

CDElement cdelem = cdeLIST.get(0);
Object obj1 = cdelem.getStudy();
Object obj2 = cdelem.getEnv();
Object obj3 = cdelem.getCDFastaheader();

boolean error = false;
boolean keepheader = false;
boolean fillEnv = false;
boolean fillStudy = false;
boolean fillFasta = false;
int id_num = 10;

if(origin.equals("uploadcsv")){ // and context exists
	fillEnv = true;
	fillStudy = true;
	fillFasta = true;
}

if(origin.equals("3b_csv")){
	fillEnv = true;
	fillStudy = true;
	fillFasta = true;
}

if(context_exists.equals("yes") & origin.equals("5")){ // and context exists
	fillEnv = true;
	fillStudy = true;
	fillFasta = true;
}

if(context_exists.equals("yes") & origin.equals("2b")){
	List<CDElement> oldLIST = (List<CDElement>) session.getAttribute("oldLIST");
	String old_study = oldLIST.get(0).getStudy().getClass().toString().substring(36).toLowerCase().trim();
	String old_env = oldLIST.get(0).getEnv().getClass().toString().substring(38).toLowerCase().trim();
	CDElement oldelement = oldLIST.get(0);
	obj3 = oldelement.getCDFastaheader();	
	
	String study = cdeLIST.get(0).getStudy().getClass().toString().toLowerCase().substring(36).trim();
	String env = cdeLIST.get(0).getEnv().getClass().toString().toLowerCase().substring(38).trim();
	
	if(study.equals(old_study)){
		fillStudy = true;
		obj1 = oldelement.getStudy();
	}
	if(env.equals(old_env)){
		fillEnv = true;
		obj2 = oldelement.getEnv();
	}
	if(study.equals(old_study) | env.equals(old_env)){
		fillFasta = true;
		obj3 = oldelement.getCDFastaheader();
	}else{
		fillFasta = false;
	}
}%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

<head>
<link rel="stylesheet" type="text/css" href="css/style.css">
<style type="text/css">
</style>
<title>DIRECT CONTEXTUAL DATA INPUT 1 TO m</title> 
<jsp:include page="googleanalytics.jsp"/>

<script type="text/javascript" src="/CDinFusion/js/numValues.js"></script>
</head>

<body>
<table border="0" width="100%" bgcolor="#2B3990" cellpadding=0 cellspacing=0>
<tr bgcolor="#ffffff">
<td width=250>
<center>
<img height="81" width="250" alt="CDinFusion Logo" src="/CDinFusion/img/logo_small_dark.png">
</center>
</td>
</tr>

<tr align="left">    
<td>
<jsp:include page="documentation/navigation.jsp"></jsp:include>
</td>
</tr>

<tr bgcolor="#ffffff">
<td>
<div class="center_div">    
<br>
<center><b> Enter contextual data</b> <br>
</center>

<center>			
<form action="upload.htm?_flowId=fileupload&amp;sessionID=<%=sessionID%>" id="fileupload" name="fileupload" method="POST" >
	<%session.setAttribute("origin", "3b");%>
	<p> If you have your filled csv file, you can upload it now:
	<input class="submitbutton" style="width: 175px" type="submit" name="Submit" value="upload" id="upload">
	</p>
</form>
</center>

<form name="Formular" action="CD_entered_1CDset_for_many.htm" method="post" accept-charset="us-ascii" onsubmit="return numValues()">
<center>
	<table>
		<tr><td>
		<!-- extend here -->
					<p>The group contains <strong><%=cdeLIST.get(0).getNumberOfSequences()%></strong> sequence IDs, they start with <br>
					the ID <strong><%=cdeLIST.get(0).getFirstSequenceID()%></strong> and end with <strong><%=cdeLIST.get(0).getLastSequenceID()%></strong>.
					</p><%
					try{ %>
					<table style="100%">
			  			<tr>
			  			<td>
					    <div style="overflow:auto; height: 400px;">
					    
						<%
						if(fillFasta){
							CDFastaHeader cdfheader = (CDFastaHeader) obj3;
							%>
							<b>information, that will be included to the FASTA header line:</b>
							<table width="100%" border="0" bgcolor="#DCDCDC" cellpadding="1">
							
							<tr>
							<td><b><font size=2>parameter</font></b></td>
							<td style="min-width:530px"><b><font size=2></font></b></td>
							<td><b><font size=2>value</font></b></td>
							</tr>

							<tr><td><b><font size=1>authority: </font></b></td>
						    <td><font size=1>The author or authors of the organism name from which sequence was obtained.</font></td>
							<td align="right"><input type="text" name="authority" class="required parameter" size="25" value="<%=cdfheader.getAuthority()%>"></td></tr>
							
							<tr><td><b><font size=1>collected by: </font></b></td>
						    <td><font size=1>Name of person who collected sample. Do not use accented or non-ASCII characters.</font></td>
							<td align="right"><input type="text" name="collectedby" class="required parameter" size="25" value="<%=cdfheader.getCollectedby()%>"></td></tr>
							
							<tr><td><b><font size=1>organism name: </font></b></td>
							<td><font size=1>taxonomic name of the sequenced organism, if unknown, e.g. <br> uncultured bacterium, uncultured archaeon, uncultured eukaryote, or uncultured organism</font></td>
							<td align="right"><input type="text" name="organism" class="required parameter" size="25" value="<%=cdfheader.getOrganism()%>"></td></tr>
							
							<tr><td><b><font size=1>isolation source: </font></b></td>
					    	<td><font size=1>ame of the sampling site/geographic location.</font></td>
							<td align="right"><input type="text" name="isolation_source" class="required parameter" size="25" value="<%=cdfheader.getIsolation_source()%>"></td></tr>
						
							</table><%
						}//end if(fillFasta)
						if(!fillFasta){%>
							<b>information, that will be included to the FASTA header line:</b>
							<table width="100%" border="0" bgcolor="#DCDCDC" cellpadding="1">
							
							<tr>
							<td><b><font size=2>parameter</font></b></td>
							<td style="min-width:530px"><b><font size=2></font></b></td>
							<td><b><font size=2>value</font></b></td>
							</tr>
							
							<tr><td><b><font size=1>authority: </font></b></td>
						    <td><font size=1>The author or authors of the organism name from which sequence was obtained.</font></td>
							<td align="right"><input type="text" name="authority" class="required parameter" size="25" value=""></td></tr>
							
							<tr><td><b><font size=1>collected by: </font></b></td>
						    <td><font size=1>Name of person who collected sample. Do not use accented or non-ASCII characters.</font></td>
							<td align="right"><input type="text" name="collectedby" class="required parameter" size="25" value=""></td></tr>
							
							<tr><td><b><font size=1>organism name: </font></b></td>
							<td><font size=1>taxonomic name of the sequenced organism, if unknown, e.g. <br> uncultured bacterium, uncultured archaeon, uncultured eukaryote, or uncultured organism</font></td>
							<td align="right"><input type="text" name="organism" class="required parameter" size="25" value=""></td></tr>
							
							<tr><td><b><font size=1>isolation source: </font></b></td>
					   		<td><font size=1>name of the sampling site/geographic location.</font></td>
							<td align="right"><input type="text" name="isolation_source" class="required parameter" size="25" value=""></td></tr>
							
							</table><%
						}//end if(!fillFasta)
						
			//<!-- studytype -->
						if(fillStudy){
							session.setAttribute("obj1", obj1);
							%>
							<jsp:include page="3_filled_study_input_fields.jsp"/>
							<%
						} //end if(fillStudy)
						if (!fillStudy){
							String study = obj1.getClass().toString().toLowerCase().substring(36);
							%>
							<jsp:include page="3_empty_study_input_fields.jsp" >
								<jsp:param name="study" value="<%=study%>" />
							</jsp:include>
							<%
						} //end if (!fillStudy)

			//<!-- env_packages --> 		  
						if(fillEnv){
							session.setAttribute("obj2", obj2);
							%>
							<jsp:include page="3_filled_env_input_fields.jsp" />
							<%
						} //end if(fillEnv)
						if(!fillEnv){
							String env = obj2.getClass().toString().toLowerCase().substring(38);
							%>
							<jsp:include page="3_empty_env_input_fields.jsp" >
								<jsp:param name="env" value="<%=env%>" />
							</jsp:include>
							<%
						} //end if(!fillEnv)
						%>
						
						</div>
						</td>
						</tr>
						<tr>
						    <td>Would you like to get a new FASTA header?
						    <select name="KeepFASTAHeader" size="1"> 
			      			<%
			      			if(keepheader == true){%>
			      				<option selected value="true">no</option>
			      			<%}
			      			else{%>
			      				<option value="true">no</option>
			      			<%}
			      			if(keepheader == false){%>
			      				<option selected value="false">yes</option>
			      			<%}
			      			else{%>
			      				<option value="false">yes</option>
			      			<%}%>
							</select></td>
			      		</tr>
					</table>
				<%}catch(Exception e){
					error = true;
					message = message +"\n ERROR IS: "+ e.getMessage();
				}%>
					download the entry as contextual data file: <input class="submitbutton" name="submit" type="submit" value="download filled csv">
					</td></tr>
					<tr align=center><td>
					<input class="submitbutton" name="submit" type="submit" value="proceed">
		
		<!-- end extension here -->
		</td></tr>
	</table>
</center>
</form>
</div>
</td>
</tr>
<tr bgcolor="#ffffff"><td align="right" height=30>
	<img height="20" width="200" alt="CDinFusion Step 3" src="/CDinFusion/img/step3.png">
</td></tr>
<jsp:include page="documentation/bottom_info.jsp"></jsp:include>
</table>
</body>
</html>